package io.renren.controller;

import java.io.IOException;
import java.io.OutputStream;
import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import io.renren.utils.*;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.util.CellRangeAddress;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;



import org.springframework.stereotype.Controller;

import io.renren.dao.DataPayrollDao;
import io.renren.dao.xtd.DataPayrollDaoXtd;
import io.renren.entity.DataPayrollEntity;
import io.renren.entity.xtd.DataAddmoneyEntityXtd;
import io.renren.entity.xtd.DataEmployeeachiRecordEntityXtd;
import io.renren.entity.xtd.DataLostmoneyEntityXtd;
import io.renren.entity.xtd.DataPayRollShow;
import io.renren.entity.xtd.DataPayrollEntityXtd;
import io.renren.entity.xtd.DictEmployeeEntityXtd;
import io.renren.entity.xtd.HisEmployeeEntityXtd;
import io.renren.entity.xtd.TransData;
import io.renren.service.DataEmployeeachiRecordService;
import io.renren.service.DataPayrollService;
import io.renren.service.SysConfigService;
import io.renren.service.xtd.DataAddmoneyServiceXtd;
import io.renren.service.xtd.DataContractpayDetailServiceXtd;
import io.renren.service.xtd.DataEmployeeachiRecordServiceXtd;
import io.renren.service.xtd.DataLostmoneyServiceXtd;
import io.renren.service.xtd.DataPayrollServiceXtd;
import io.renren.service.xtd.DictEmployeeServiceXtd;
import io.renren.service.xtd.HisEmployeeServiceXtd;


/**
 * 
 * 
 * @author chenshun
 * @email sunlightcs@gmail.com
 * @date 2018-06-05 09:32:07
 */
@Controller
@RequestMapping("datapayroll")
public class DataPayrollController {
	@Autowired
	private DataPayrollService dataPayrollService;
	@Autowired
	private DataPayrollDao dataPayrollDao;
	@Autowired
	private DataPayrollDaoXtd dataPayrollDaoXtd;
	@Autowired
	private DataContractpayDetailServiceXtd dataContractpayDetailServiceXtd;
	@Autowired
	private DataAddmoneyServiceXtd dataAddmoneyServiceXtd;
	@Autowired
	private DataLostmoneyServiceXtd dataLostmoneyServiceXtd;
	@Autowired
	private DataPayrollServiceXtd dataPayrollServiceXtd;
	@Autowired
	private HisEmployeeServiceXtd hisEmployeeServiceXtd;
	@Autowired
	private DictEmployeeServiceXtd dictEmployeeServiceXtd;
	@Autowired
	private SysConfigService sysConfigService;
	@Autowired
	private DataEmployeeachiRecordServiceXtd dataEmployeeachiRecordServiceXtd;
	@RequestMapping("/datapayroll.html")
	public String list(){
		return "datapayroll/datapayroll.html";
	}

	/**
	 * 列表
	 */
	@ResponseBody
	@RequestMapping("/list")
	@RequiresPermissions("datapayroll:list")
	public R list(Integer page, Integer limit,String sort,String order,String value,String calTime){
		Map<String, Object> map = new HashMap<>();
		map.put("offset",0);
		map.put("limit", 1);
		List<DataPayrollEntity> queryList = dataPayrollDao.queryList(map);
		String thisTime = queryList.get(0).getPayrollmonth();
		List<DataPayrollEntityXtd> dataPayrollList=null;
		int total=0;
		if(calTime==null) {
			calTime=thisTime;
			Map<String, Object> map2 = new HashMap<>();
			map2.put("offset", (page - 1) * limit);
			map2.put("limit", limit);
			map2.put("value", value);
			map2.put("calTime", calTime);
			if (sort.isEmpty() || sort == null) {
				map2.put("orderby", " ORDER BY e.deptNo asc, e.jobNo DESC ");
			} else {
				map2.put("orderby", " order by " + sort + " " + order + " ");
			}
			//查询列表数据
			dataPayrollList = dataPayrollDaoXtd.queryListXtd(map2);
			total = dataPayrollService.queryTotal(map2);
		}else if(calTime.equals(thisTime)) {
			Map<String, Object> map2 = new HashMap<>();
			map2.put("offset", (page - 1) * limit);
			map2.put("limit", limit);
			map2.put("value", value);
			map2.put("calTime", calTime);
			if (sort.isEmpty() || sort == null) {
				map2.put("orderby", " ORDER BY e.deptNo asc, e.jobNo DESC ");
			} else {
				map2.put("orderby", " order by " + sort + " " + order + " ");
			}
			//查询列表数据
			dataPayrollList = dataPayrollDaoXtd.queryListXtd(map2);
			total = dataPayrollService.queryTotal(map2);
		}else{
			String calTimeEx=calTime;
			if(Integer.parseInt(calTime.split("-")[1])<10) {
				calTimeEx=calTime.substring(0,5)+calTime.substring(6,7);
			}
			Map<String, Object> map2 = new HashMap<>();
			map2.put("offset", (page - 1) * limit);
			map2.put("limit", limit);
			map2.put("value", value);
			map2.put("calTime", calTime);
			map2.put("calTimeEx", calTimeEx);
			if (sort.isEmpty() || sort == null) {
				map2.put("orderby", " ORDER BY e.deptNo asc, e.jobNo DESC ");
			} else {
				map2.put("orderby", " order by " + sort + " " + order + " ");
			}
			//查询列表数据
			dataPayrollList = dataPayrollDaoXtd.queryListXtd2(map2);
			total = dataPayrollService.queryTotal(map2);
		}


		PageUtils pageUtil = new PageUtils(dataPayrollList, total, limit, page);

		return R.ok().put("page", pageUtil);
	}


	@ResponseBody
	@RequestMapping("/list1")

	public R list1(Integer page, Integer limit,String sort,String order,String value,String calTime,String no){
		Map<String, Object> map = new HashMap<>();
		map.put("offset",0);
		map.put("limit", 1);
		List<DataPayrollEntity> queryList = dataPayrollDao.queryList(map);
		Date now=new Date();
		SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM");
		String thisTime=dateFormat.format(now);
		no=ShiroUtils.getUserEntity().getUsername();
		List<DataPayrollEntityXtd> dataPayrollList=null;
		int total=0;
		if(calTime==null) {
			calTime=thisTime;
			Map<String, Object> map2 = new HashMap<>();
			map2.put("offset", (page - 1) * limit);
			map2.put("limit", limit);
			map2.put("value", value);
			map2.put("calTime", calTime);
			map2.put("workNo",no);

			//查询列表数据
			dataPayrollList = dataPayrollDaoXtd.queryListXtd1(map2);
			total = dataPayrollService.queryTotal(map2);
		}


		PageUtils pageUtil = new PageUtils(dataPayrollList, total, limit, page);

		return R.ok().put("page", pageUtil);
	}


	/**
	 * 信息
	 */
	@ResponseBody
	@RequestMapping("/info/{id}")
	@RequiresPermissions("datapayroll:info")
	public R info(@PathVariable("id") String id){
		DataPayrollEntity dataPayroll = dataPayrollService.queryObject(id);

		return R.ok().put("dataPayroll", dataPayroll);
	}

	/**
	 * 保存
	 */
	@ResponseBody
	@RequestMapping("/save")
	@RequiresPermissions("datapayroll:save")
	public R save(@RequestBody DataPayrollEntity dataPayroll){
		dataPayrollService.save(dataPayroll);

		return R.ok();
	}

	/**
	 * 修改
	 */
	@ResponseBody
	@RequestMapping("/update")
	@RequiresPermissions("datapayroll:update")
	public R update(@RequestBody DataPayrollEntity dataPayroll){
		dataPayrollService.update(dataPayroll);

		return R.ok();
	}

	/**
	 * 删除
	 */
	@ResponseBody
	@RequestMapping("/delete")
	@RequiresPermissions("datapayroll:delete")
	public R delete(@RequestBody String[] ids){
		dataPayrollService.deleteBatch(ids);

		return R.ok();
	}
	/**
	 * 获得数据库最新计算日期
	 */
	@ResponseBody
	@RequestMapping(value="/date" ,method = RequestMethod.GET)
	public R getDate(){
		DataPayrollEntity newRecord = dataPayrollService.getNewRecord();
		if(newRecord!=null) {
			String payrollmonth = newRecord.getPayrollmonth();
			return R.ok().put("payrollmonth", payrollmonth);
		}else {
			return R.ok().put("payrollmonth", null);
		}		
	}

	/**
	 * 信息
	 */
	@ResponseBody
	@RequestMapping(value="/infoXtd",method = RequestMethod.POST)
	public R infoXtd(@RequestBody TransData data){
		String month = data.getMonth();
		String workNo = data.getWorkNo();
		//根据工号和收款日期查找该员工的合同记录
		Map<String, Object> map=new HashMap<>();
		map.put("workNo", workNo);
		map.put("month", month);
		String year="";
		String monthk="";
		List<DataPayRollShow> payShowInfo = dataContractpayDetailServiceXtd.getPayShowInfo(map);
		if(month!=null) {
			String[] split = month.split("-");
			year=split[0];
			monthk=split[1];

		}
		Map<String, Object> mapp=new HashMap<>();
		mapp.put("workNo", workNo);
		mapp.put("year", year);
		mapp.put("month", monthk);
		List<DataAddmoneyEntityXtd> addByList = dataAddmoneyServiceXtd.getAddByPar(mapp);
		List<DataLostmoneyEntityXtd> lostByList = dataLostmoneyServiceXtd.getLostByPar(mapp);
		return R.ok().put("payShowInfo", payShowInfo).put("addByList", addByList).put("lostByList", lostByList);

	}

	/**
	 * 信息
	 * @throws ParseException 
	 */
	@ResponseBody
	@RequestMapping(value="/talent/{workNo}",method = RequestMethod.GET)
	public R talentInfo(@PathVariable("workNo") String workNo) throws ParseException{
		List<DataPayrollEntityXtd> queryByWorkno = dataPayrollServiceXtd.queryByWorkno(workNo);
		List<DataPayrollEntityXtd> queryByWorknoNew=new ArrayList<>();
		DictEmployeeEntityXtd querySingleXtd = dictEmployeeServiceXtd.querySingleXtd(workNo);
		//最早的计算工资时间
		Integer hasPorts=null;
		Integer hasPorts2=null;
		Integer count=0;
		boolean flag=false;
		boolean flag2=false;
		Date inorgtime = querySingleXtd.getInorgtime();
		//判断入职月开不开端口
		SimpleDateFormat newSdf=new SimpleDateFormat("yyyy-MM");
		String payrollmonth = newSdf.format(inorgtime);
		
		Map<String, Object> map=new HashMap<>();
		map.put("workNo", workNo);
		map.put("hisyear", payrollmonth.split("-")[0]);
		map.put("hismonth", payrollmonth.split("-")[1]);
		//第二个月
		String preMonth = DateUtils.getPreMonth(payrollmonth);
		Map<String, Object> map2=new HashMap<>();
		map2.put("workNo", workNo);
		map2.put("hisyear", preMonth.split("-")[0]);
		map2.put("hismonth", preMonth.split("-")[1]);
		//是否享有首月3900底薪	
		HisEmployeeEntityXtd queryEmployeeByInOrgTime = hisEmployeeServiceXtd.queryEmployeeByInOrgTime(map);
		HisEmployeeEntityXtd queryEmployeeByInOrgTime2 = hisEmployeeServiceXtd.queryEmployeeByInOrgTime(map2);
		if(queryEmployeeByInOrgTime==null) {
			//找不到则去现在的人力表找

			hasPorts = querySingleXtd.getHasFirstPort();
			if(hasPorts==1) {
				flag=true;
			}
		}else {
			hasPorts = queryEmployeeByInOrgTime.getHasFirstPort();
			if(hasPorts==1) {
				flag=true;
			}else {
				if(queryEmployeeByInOrgTime2==null) {
					hasPorts2 = querySingleXtd.getHasFirstPort();
					if(hasPorts2==1) {
						flag2=true;
					}

				}else {
					hasPorts2 = queryEmployeeByInOrgTime2.getHasFirstPort();
					if(hasPorts2==1) {
						flag2=true;
					}
				}
			}
		}


		BigDecimal sum=new BigDecimal(0);

		//开端口

		for (int i = 0; i < queryByWorkno.size(); i++) {
			DataPayrollEntityXtd dataPayrollEntityXtd = queryByWorkno.get(i);
			BigDecimal firstmonthwage = dataPayrollEntityXtd.getFirstmonthwage();
			BigDecimal monthwage = dataPayrollEntityXtd.getMonthwage();
			BigDecimal businesspromotion = dataPayrollEntityXtd.getBusinesspromotion();
			String jobNo = dataPayrollEntityXtd.getJobno();
			if("02".equals(jobNo)) {
				count++;
				continue;
			}
			if(firstmonthwage==null) {
				firstmonthwage=new BigDecimal(0);
			}else if(monthwage==null) {
				monthwage=new BigDecimal(0);
			}else if(businesspromotion==null) {
				businesspromotion=new BigDecimal(0);
			}

			sum=sum.add(firstmonthwage).add(monthwage).add(businesspromotion);
			/*sum=sum.divide(new BigDecimal(4),2,BigDecimal.ROUND_HALF_UP);*/
			queryByWorknoNew.add(dataPayrollEntityXtd);
		}

		if(flag==true||flag2==true) {
			//享受过3900待遇
			String value = sysConfigService.getValue("firstOfSalary", null);
			sum=(sum.subtract(new BigDecimal(value))).divide(new BigDecimal(4),2, BigDecimal.ROUND_HALF_UP);
		}else {
			//没有3900部分，这里说明一直没开端口，要看入职月业绩

			//去记录表查询改签约日累计底薪，超过5000则不要减去1500
			SimpleDateFormat sdf=new SimpleDateFormat("yyyyMM");
			String format = sdf.format(inorgtime);
			Map<String, Object> queryMap=new HashMap<>();
			queryMap.put("recordTime", format);
			queryMap.put("employeeId", querySingleXtd.getId());
			List<DataEmployeeachiRecordEntityXtd> queryNewestRecord = dataEmployeeachiRecordServiceXtd.queryNewestRecord(queryMap);
			BigDecimal dx=new BigDecimal(1500);
			//入职当月业绩不为空
			if(queryNewestRecord.size()!=0) {
				DataEmployeeachiRecordEntityXtd dataEmployeeachiRecordEntityXtd = queryNewestRecord.get(0);
				BigDecimal totalachievement = dataEmployeeachiRecordEntityXtd.getTotalachievement();
				dx = CalculateUtils.getCoefficient(sysConfigService, totalachievement,"dxqj");
			}

			String dxqj = sysConfigService.getValue("achievement.dxqj1", null);
			String value =dxqj.split("-")[2];
			//首月获得的底薪大于最低1500标准，全部打折，这边全部返还
			if(dx.compareTo(new BigDecimal(value))==1) {
				sum=sum.divide(new BigDecimal(4),2,BigDecimal.ROUND_HALF_UP);
			}else {
				//不大于1500，则减去1500，返还
				//一直是02职级，不存在返还
				if(queryByWorkno.size()==count) {
					sum=new BigDecimal(0);
				}else {
					//这里的1500可能因为出勤天数发不完，找到入职当月的实发底薪
					BigDecimal firstmonthwage=new BigDecimal(0);
					SimpleDateFormat sd=new SimpleDateFormat("yyyy-MM");
					String inorg = sd.format(inorgtime);
					Map<String, Object> queryMap2=new HashMap<>();
					queryMap2.put("employeeId", querySingleXtd.getId());
					queryMap2.put("payrollMonth", inorg);
					DataPayrollEntityXtd queryByEmployeeIdAndMonth = dataPayrollServiceXtd.queryByEmployeeIdAndMonth(queryMap2);
					if(queryByEmployeeIdAndMonth!=null) {
						//如果入职月没有记录，则不减
						firstmonthwage = queryByEmployeeIdAndMonth.getFirstmonthwage();
					}

					sum=(sum.subtract(firstmonthwage)).divide(new BigDecimal(4),2, BigDecimal.ROUND_HALF_UP);
				}

			}
		}
		return R.ok().put("dataPayroll", queryByWorknoNew).put("sum", sum);
	}

	@SuppressWarnings("deprecation")
	@RequestMapping(value="/outExcel",method = RequestMethod.POST )
	public String exportExcel(@RequestParam(name="calTime") String calTime,HttpServletResponse response) throws IOException {
		Map<String, Object> map = new HashMap<>();
		map.put("offset",0);
		map.put("limit", 1);
		List<DataPayrollEntity> queryList = dataPayrollDao.queryList(map);
		String thisTime = queryList.get(0).getPayrollmonth();
		List<DataPayrollEntityXtd> list=null;
		if(calTime==null||calTime=="") {
			calTime=thisTime;
			Map<String, Object> map2 = new HashMap<>();
			map2.put("calTime", calTime);
			map2.put("orderby", " ORDER BY payrollMonth desc, e.jobNo DESC ");
			list = dataPayrollDaoXtd.queryListXtd(map2);
		}else if(calTime.equals(thisTime)) {
			Map<String, Object> map2 = new HashMap<>();

			map2.put("calTime", calTime);
			map2.put("orderby", " ORDER BY payrollMonth desc, e.jobNo DESC ");
			//查询列表数据
			list = dataPayrollDaoXtd.queryListXtd(map2);
		}else{
			String calTimeEx=calTime;
			if(Integer.parseInt(calTime.split("-")[1])<10) {
				calTimeEx=calTime.substring(0,5)+calTime.substring(6,7);
			}
			Map<String, Object> map2 = new HashMap<>();

			map2.put("calTime", calTime);
			map2.put("calTimeEx", calTimeEx);
			map2.put("orderby", " ORDER BY payrollMonth desc, e.jobNo DESC ");
			//查询列表数据
			list = dataPayrollDaoXtd.queryListXtd2(map2);
		}
		HSSFWorkbook wb = new HSSFWorkbook();
		// 建立新的sheet对象（excel的表单）
		HSSFSheet sheet = wb.createSheet(calTime+"工资单");

		// 在sheet里创建第一行，参数为行索引(excel的行)，可以是0～65535之间的任何一个
		HSSFRow row1 = sheet.createRow(0);
		// 创建单元格（excel的单元格，参数为列索引，可以是0～255之间的任何一个
		HSSFCell cell = row1.createCell(0);
		// 设置单元格内容
		cell.setCellValue(calTime+"工资单");
		// 合并单元格CellRangeAddress构造参数依次表示起始行，截至行，起始列， 截至列
		sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 3));
		// 在sheet里创建第二行
		HSSFRow row2 = sheet.createRow(1);
		// 创建单元格并设置单元格内容
		row2.createCell(0).setCellValue("姓名");
		row2.createCell(1).setCellValue("工号");
		row2.createCell(2).setCellValue("职位编号");
		row2.createCell(3).setCellValue("首月底薪");
		row2.createCell(4).setCellValue("底薪");
		row2.createCell(5).setCellValue("端口津贴");
		row2.createCell(6).setCellValue("话费补助");
		row2.createCell(7).setCellValue("业务提成");
		row2.createCell(8).setCellValue("单列收入");		
		row2.createCell(9).setCellValue("新人推荐奖");
		row2.createCell(10).setCellValue("主管直接管理津贴");
		row2.createCell(11).setCellValue("主管间接管理津贴");
		row2.createCell(12).setCellValue("职务津贴");
		row2.createCell(13).setCellValue("分行直接管理津贴");
		row2.createCell(14).setCellValue("分行间接管理津贴");
		row2.createCell(15).setCellValue("区域直接管理津贴");
		row2.createCell(16).setCellValue("区域间接管理津贴");
		row2.createCell(17).setCellValue("大区直接管理津贴");
		row2.createCell(18).setCellValue("大区间接管理津贴");		
		row2.createCell(19).setCellValue("社保");
		row2.createCell(20).setCellValue("住房公积金");
		row2.createCell(21).setCellValue("加款");
		row2.createCell(22).setCellValue("扣款");
		row2.createCell(23).setCellValue("总计");
		for (int i = 0; i < list.size(); i++) {
			HSSFRow row3 = sheet.createRow(i + 2);
			row3.createCell(0).setCellValue(list.get(i).getName());
			row3.createCell(1).setCellValue(list.get(i).getWorkNo());
			row3.createCell(2).setCellValue(list.get(i).getJobno());
			if(list.get(i).getFirstmonthwage()!=null) {
				row3.createCell(3).setCellValue(list.get(i).getFirstmonthwage().doubleValue());
			}
			if(list.get(i).getMonthwage()!=null) {
				row3.createCell(4).setCellValue(list.get(i).getMonthwage().doubleValue());
			}
			if(list.get(i).getPortfee()!=null) {
				row3.createCell(5).setCellValue(list.get(i).getPortfee().doubleValue());
			}
			if(list.get(i).getMobilefee()!=null) {
				row3.createCell(6).setCellValue(list.get(i).getMobilefee().doubleValue());
			}
			if(list.get(i).getBusinesspromotion()!=null) {
				row3.createCell(7).setCellValue(list.get(i).getBusinesspromotion().doubleValue());
			}
			if(list.get(i).getSeparateMoney()!=null) {
				row3.createCell(8).setCellValue(list.get(i).getSeparateMoney().doubleValue());
			}
			if(list.get(i).getNewrecommend()!=null) {
				row3.createCell(9).setCellValue(list.get(i).getNewrecommend().doubleValue());
			}
			if(list.get(i).getDirectordirect()!=null) {
				row3.createCell(10).setCellValue(list.get(i).getDirectordirect().doubleValue());
			}
			if(list.get(i).getDirectorindirect()!=null) {
				row3.createCell(11).setCellValue(list.get(i).getDirectorindirect().doubleValue());
			}
			if(list.get(i).getJoballowance()!=null) {
				row3.createCell(12).setCellValue(list.get(i).getJoballowance().doubleValue());
			}
			if(list.get(i).getBranchdirect()!=null) {
				row3.createCell(13).setCellValue(list.get(i).getBranchdirect().doubleValue());
			}
			if(list.get(i).getBranchindirect()!=null) {
				row3.createCell(14).setCellValue(list.get(i).getBranchindirect().doubleValue());
			}
			if(list.get(i).getAreadirect()!=null) {
				row3.createCell(15).setCellValue(list.get(i).getAreadirect().doubleValue());
			}
			if(list.get(i).getAreaindirect()!=null) {
				row3.createCell(16).setCellValue(list.get(i).getAreaindirect().doubleValue());		
			}
			if(list.get(i).getBigareadirect()!=null) {
				row3.createCell(17).setCellValue(list.get(i).getBigareadirect().doubleValue());
			}
			if(list.get(i).getBigareaindirect()!=null) {
				row3.createCell(18).setCellValue(list.get(i).getBigareaindirect().doubleValue());
			}
			if(list.get(i).getSocialinsurance()!=null) {
				row3.createCell(19).setCellValue(list.get(i).getSocialinsurance().doubleValue());
			}
			if(list.get(i).getHousingfund()!=null) {
				row3.createCell(20).setCellValue(list.get(i).getHousingfund().doubleValue());
			}
			if(list.get(i).getReward()!=null) {
				row3.createCell(21).setCellValue(list.get(i).getReward().doubleValue());
			}
			if(list.get(i).getPunishment()!=null) {
				row3.createCell(22).setCellValue(list.get(i).getPunishment().doubleValue());
			}
			if(list.get(i).getTotalMoney()!=null) {
				row3.createCell(23).setCellValue(list.get(i).getTotalMoney().doubleValue());
			}
		}
		// 输出Excel文件
		Date date = new Date();
		SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		String mat = format.format(date);
		OutputStream output = response.getOutputStream();
		response.reset();
		String fileName = calTime+"工资单";
		response.setHeader("Content-Disposition",
				"filename=" + new String(fileName.getBytes("gb2312"), "iso8859-1") + mat + ".xls");// 设置文件头编码方式和文件名
		// response.setHeader("Content-disposition", "attachment;
		// filename=销售汇总表" + mat + ".xls");
		response.setContentType("application/msexcel");
		wb.write(output);
		output.close();
		return null;
	}
}
